package com.fxu.role.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

import javax.validation.Valid;

/***
 * <p>fxu</p>
 * 管理员表：[admin]的数据实体类
 * @author fangxu
 * @version 2021-06-03
 ***/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Admin", description = "管理员")
@TableName("fxu_admin")
public class Admin extends SEntity<Admin> implements Serializable {
/*=== 自动生成代码 开始 ===*/
    private static final long serialVersionUID = 3086905374105188054L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "手机", required = true)
    @NotBlank(message = "手机必须赋值")
    @Size(max = 16, message = "手机的长度必须小于16位")
    private String phone;

    @JsonIgnore
    @ApiModelProperty(value = "密码", required = true)
    @NotBlank(message = "密码必须赋值")
    @Size(max = 32, message = "密码的长度必须小于32位")
    private String password;

    @ApiModelProperty(value = "真名")
    @Size(max = 16, message = "真名的长度必须小于16位")
    private String name;

    @ApiModelProperty(value = "头像")
    @Size(max = 255, message = "头像的长度必须小于255位")
    private String avatar;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态[1:正常,0:删除]")
    @EnumValid(target = StatusEnum.class, message = "状态的值必须为[1:正常,0:删除]")
    private Integer status;

    @TableField(fill = UPDATE, update = "%s+1")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @Valid
    @TableField(exist = false)
    @ApiModelProperty(value = "用户角色")
    @Cascade(thisField = "id", linkField = "adminId", save = true)
    private List<AdminRole> adminRoleList;

    /**
     * 获得状态的说明
     * @return 状态说明
     */
    public String getStatusText() {
        return StatusEnum.desc(status);
    }
/*=== 自动生成代码 结束 ===*/
}
